messingaround.ipynb
No Headings
The table of contents shows headings in notebooks and supported files.
- File
- Edit
- View
- Run
- Kernel
- Settings
- Help
Kernel status: Idle Executed 1 cellElapsed time: 6 seconds
[52]:
%gui osx
[53]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
def create_wavy_pattern(width=800, height=600, num_lines=100, frequency=0.02, amplitude=30):
# Set up the figure
plt.figure(figsize=(20, 15), facecolor='black')
ax = plt.gca()
ax.set_facecolor('black')
# Create base y-coordinates for lines (evenly spaced)
y_base = np.linspace(0, height, num_lines)
# Create x-coordinates
x = np.linspace(0, width, 1000)
# Create each wavy line
for y_start in y_base:
# Create wave deformation
# Use multiple sine waves for more organic look
deformation = (
amplitude * np.sin(frequency * x + y_start/50) +
amplitude/2 * np.sin(frequency*2 * x - y_start/30) +
amplitude/4 * np.sin(frequency/2 * x + y_start/20)
)
# Add the deformation to the base y-position
y = y_start + deformation
# Plot the line
plt.plot(x, y, color='white', linewidth=1, alpha=1)
# Set the display parameters
plt.axis('off')
plt.xlim(0, width)
plt.ylim(0, height)
# Remove padding
plt.tight_layout(pad=0)
# Display the plot
plt.show()
# Generate the pattern
create_wavy_pattern(
width=800,
height=600,
num_lines=120, # Adjust for line density
frequency=0.015, # Adjust for wave frequency
amplitude=40 # Adjust for wave height
)
# Optionally save the image
# plt.savefig('wavy_pattern.png', bbox_inches='tight', pad_inches=0, dpi=300, facecolor='black')
[26]:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
%matplotlib inline
from IPython.display import HTML
class WaveAnimator:
def __init__(self, width=800, height=600, num_lines=100, frequency=0.02, amplitude=30):
self.width = width
self.height = height
self.num_lines = num_lines
self.frequency = frequency
self.amplitude = amplitude
# Set up the figure
self.fig = plt.figure(figsize=(4, 3), facecolor='black')
self.ax = plt.gca()
self.ax.set_facecolor('black')
# Create base coordinates
self.y_base = np.linspace(0, height, num_lines)
self.x = np.linspace(0, width, 1000)
# Initialize empty line objects
self.lines = []
for _ in range(num_lines):
line, = self.ax.plot([], [], color='white', linewidth=1, alpha=1)
self.lines.append(line)
# Set the display parameters
plt.axis('off')
plt.xlim(0, width)
plt.ylim(0, height)
plt.tight_layout(pad=0)
def init(self):
for line in self.lines:
line.set_data([], [])
return self.lines
def animate(self, frame):
# Convert frame to radians for smoother cyclic effects
t = frame * 2 * np.pi / 100
# Update each line
for i, line in enumerate(self.lines):
y_start = self.y_base[i]
# Dynamic amplitude modulation
amp_mod = 1 + 0.3 * np.sin(t/2 + y_start/100)
# Dynamic frequency modulation
freq_mod = 1 + 0.2 * np.cos(t/3 + y_start/200)
# Create wave deformation with multiple dynamic components
deformation = (
# Primary wave with moving phase and amplitude modulation
self.amplitude * amp_mod * np.sin(
self.frequency * freq_mod * self.x + y_start/50 + t
) +
# Secondary wave with different phase and direction
self.amplitude/2 * np.sin(
self.frequency*2 * self.x - y_start/30 + t*1.5 +
0.1 * np.sin(t/2) # Phase distortion
) +
# Tertiary wave for complexity
self.amplitude/4 * np.sin(
self.frequency/2 * self.x + y_start/20 - t*0.7
) +
# Breathing effect
self.amplitude/3 * np.sin(t/2) * np.sin(self.x/200 + y_start/100) +
# Standing wave pattern
self.amplitude/5 * np.sin(t) * np.sin(self.x/100)
)
# Add vertical drift
vertical_drift = 10 * np.sin(t/3 + y_start/100)
# Set the new line data
line.set_data(self.x, y_start + deformation + vertical_drift)
return self.lines
def create_animated_pattern():
animator = WaveAnimator(
width=800,
height=600,
num_lines=120,
frequency=0.015,
amplitude=40
)
# Create animation
anim = FuncAnimation(
animator.fig,
animator.animate,
init_func=animator.init,
frames=200,
interval=40,
blit=True
[26]:
[19]:
[20]:
[22]:
Selection deleted
from IPython.display import HTML, Image, clear_output
import base64
from datetime import datetime
import ipywidgets as widgets
from matplotlib.animation import PillowWriter
# Create control widgets
num_lines = widgets.IntSlider(
value=400,
min=100,
max=800,
description='Lines:',
style={'description_width': 'initial'}
)
frequency = widgets.FloatSlider(
value=0.015,
min=0.005,
max=0.03,
step=0.001,
description='Frequency:',
style={'description_width': 'initial'}
)
amplitude = widgets.IntSlider(
value=40,
min=10,
max=80,
description='Amplitude:',
style={'description_width': 'initial'}
)
fps_slider = widgets.IntSlider(
create_animation(None)
Quick preview version:
[29]:
160
0.30
1.00
0.10
146
0.35
1.50
0.50
333
4
0.50
Pinch Point 1
0.90
0.10
0.10
Pinch Point 2
0.90
0.10
0.10
Pinch Point 3
0.40
0.20
0.10
Pinch Point 4
0.10
0.40
0.10
Importing py5 on macOS but the necessary Jupyter macOS event loop has not been activated. I'll activate it for you, but next time, execute `%gui osx` before importing this library.
100
2
0.50
Flow Pattern 1
0.20
0.50
0.20
1.00
Flow Pattern 2
0.40
0.50
0.20
1.00
Flow Pattern 3
0.60
0.50
0.20
1.00
Flow Pattern 4
0.80
0.50
0.20
1.00
--------------------------------------------------------------------------- Exception Traceback (most recent call last) File PApplet.java:1761, in processing.core.PApplet.createGraphics() Exception: Java Exception The above exception was the direct cause of the following exception: java.lang.NullPointerException Traceback (most recent call last) /var/folders/s4/y20zrdnj7yl52r9qt_41h5380000gn/T/ipykernel_45251/3212741496.py in ?(button) 189 def update_art(button): --> 190 with output: 191 clear_output(wait=True) 192 display(create_separate_flows()) /var/folders/s4/y20zrdnj7yl52r9qt_41h5380000gn/T/ipykernel_45251/3212741496.py in ?(width, height) 118 def create_separate_flows(width=1200, height=600): --> 119 art = py5.create_graphics(width, height) 120 121 def generate_single_flow(center_x, center_y, flow_width, spread, line_count): 122 # Generate one complete flow pattern /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/py5/__init__.py in ?(*args) 4459 with `create_graphics()` can have transparency. This makes it possible to draw 4460 into a graphics and maintain the alpha channel. By using `save()` to write a 4461 `PNG` or `TGA` file, the transparency of the graphics object will be honored. 4462 """ -> 4463 return _py5sketch.create_graphics(*args) /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/py5/graphics.py in ?(self_, *args) 50 @functools.wraps(f) 51 def decorated(self_, *args): ---> 52 ret = f(self_, *args) 53 if ret is not None: 54 return Py5Graphics(ret) /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/py5/sketch.py in ?(self, *args) 9120 with `create_graphics()` can have transparency. This makes it possible to draw 9121 into a graphics and maintain the alpha channel. By using `save()` to write a 9122 `PNG` or `TGA` file, the transparency of the graphics object will be honored. 9123 """ -> 9124 return self._instance.createGraphics(*args) java.lang.NullPointerException: java.lang.NullPointerException: Cannot invoke "processing.core.PGraphics.isGL()" because "this.g" is null
2024-10-25 13:19:39.177 Python[45251:1680429] WARNING: Secure coding is not enabled for restorable state! Enable secure coding by implementing NSApplicationDelegate.applicationSupportsSecureRestorableState: and returning YES.
36
4
0.30
0.90
125.00
Flow 1
0.20
0.30
Flow 2
0.40
0.70
Flow 3
0.40
0.30
Flow 4
0.80
0.30
4
50
0.10
0.50
100
200
[11]:
1/6
-
Variables
Callstack
Breakpoints
Source
9
1
Kernel Sources
Common Tools
No metadata.
Advanced Tools
No metadata.
